package com.atguigu.bigdata.spark.core.rdd.operator.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.Optional;
import scala.Tuple2;

import java.util.Arrays;
import java.util.List;

public class Spark22_RDD_Operator_Transform_JAVA {
    public static void main(String[] args) {
        // TODO 算子 - (Key - Value类型)
        //左连接 右连接
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);


        List<Tuple2<String, Integer>> list = Arrays.asList(new Tuple2<String,Integer>("a", 1),
                new Tuple2<String,Integer>("a",2), new Tuple2<String, Integer>("c", 3));
        JavaPairRDD<String, Integer> rdd1 = sc.<String, Integer> parallelizePairs(list);
        List<Tuple2<String, Integer>> list1 = Arrays.asList(new Tuple2<String,Integer>("a", 5),
                new Tuple2<String,Integer>("a",4), new Tuple2<String, Integer>("c", 6));
        JavaPairRDD<String, Integer> rdd2 = sc.<String, Integer> parallelizePairs(list1);
        JavaPairRDD<String, Tuple2<Integer, Optional<Integer>>> res = rdd1.leftOuterJoin(rdd2);
        System.out.println(res.collect().toString());



    }
}
